#@head() 
#@header()
<title>营销管理</title>
#@aside("marketing")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<div class="content-wrapper">
	<section class="content">
		<div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
              <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">领取详情</a></li>
            </ul>
            <div class="tab-content">
              <div class="tab-pane active" id="tab_1">
				<label style="float:left;margin-top:17px;margin-left:20px;">时间区间:</label>
				<input type="text" id="startime" class="form-control" onClick="WdatePicker()" style="width:120px;float:left;margin-top:10px;margin-left:10px;">
				<span style="float:left;margin:15px 5px 0 5px;">—</span>
				<input type="text" id="endtime" class="form-control" onClick="WdatePicker()" style="width:120px;float:left;margin-top:10px;margin-right:20px;">
				<div class="input-group margin" style="width:400px;float:left">
				<input id="mobile" type="text" placeholder="请输入手机号" class="form-control"  >
				<span class="input-group-btn">
				  <button id="bidseach" type="button" class="btn btn-info btn-flat">搜索</button>
				</span>
			</div>
				<div class="box-body">
					<table id="example1" class="table table-striped">
						<thead>
							<tr>
								<th>用户名</th>
								<th>真实姓名</th>
								<th>领取额度</th>
								<th>领取时间</th>
								<th>使用时间</th>
								<th>状态</th>
								<th>使用详情</th>
							</tr>
						</thead>
						
						<tbody id="datalist">
						</tbody>
					</table>
				</div>
				<div class="box-footer clearfix">
				  <ul class="pagination pagination-sm no-margin pull-right">
					<li id="datalist1"><a href="#">首页</a></li>
					<li id="datalist2"><a href="#">上一页</a></li>
					<li><a href="#">第<span id="datalist5"></span>页 共<span id="datalist6"></span>页</a></li>
					<li id="datalist3"><a href="#">下一页</a></li>
					<li id="datalist4"><a href="#">尾页</a></li>
				  </ul>
				</div>
              </div>
            </div>
            <!-- /.tab-content -->
          </div>
		  
	</section>
</div>
#@footer()
<script id="datalistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${mobile}</td>
		<td>${real_name}</td>
		<td>${amount}</td>
		<td>${create_time}</td>
		<td>${apply_time}</td>
		<td>${status}</td>
		<td>${summary}</td>
	</tr>
</script>
<script>
var totalPage = 1;
var pageNumber = 1;
var startime = "";
var endtime = "";
var mobile = "";
$(document).ready(function(){
	pageNumber = 1;
	$("#datalist").empty();
	datalist(1,startime,endtime,mobile);
	$("#datalist5").html(pageNumber);
});
$("#datalist1").click(function(){
	$("#datalist").empty();
	datalist(1,startime,endtime,mobile);
	pageNumber = 1;
	$("#datalist5").html(pageNumber);
});
$("#datalist2").click(function(){
	if(pageNumber==1){
		alert("当前页是首页!");
	}else{
	$("#datalist").empty();
	pageNumber = pageNumber-1;
	datalist(pageNumber,startime,endtime,mobile);
	$("#datalist5").html(pageNumber);
	}
});
$("#datalist3").click(function(){
	if(pageNumber==totalPage){
		alert("当前页是尾页!");
	}else{
	$("#datalist").empty();
	pageNumber = pageNumber +1; 
	datalist(pageNumber,startime,endtime,mobile);
	$("#datalist5").html(pageNumber);
	}
});
$("#datalist4").click(function(){
	$("#datalist").empty();
	datalist(totalPage,startime,endtime,mobile);
	pageNumber = totalPage;
	$("#datalist5").html(pageNumber);
});
$("#bidseach").click(function(){
	$("#datalist").empty();
	if(!$.isBlank($("#startime").val())){
		startime = $("#startime").val()+" 00:00:00";
	}
	if(!$.isBlank($("#endtime").val())){
		endtime = $("#endtime").val()+" 24:00:00";
	}
	mobile = $("#mobile").val();
	datalist(1,startime,endtime,mobile);
	pageNumber = 1;
	$("#shall5").html(pageNumber);
});
function datalist(page,startime,endtime,mobile){
	var params = GetRequest();
	console.log("/couponLog/list?token=#(session.token??)&couponId="+params['id']+"&page="+page+"&size=12&createTimeStart="+startime+"&createTimeEnd="+endtime+"&mobile="+mobile);
	$.getJSON("/couponLog/list?token=#(session.token??)&couponId="+params['id']+"&page="+page+"&size=12&createTimeStart="+startime+"&createTimeEnd="+endtime+"&mobile="+mobile, function(datainfo) {
		totalPage = datainfo.data.page.totalPage;  
		$("#datalist6").html(totalPage); 
		$.each(datainfo.data.page.list, function(i, item){ 
			if(item.status=="normal"){var status="未使用"}else if(item.status=="used"){var status="已使用"}else if(item.status=="expire"){var status="已过期"}
			var datalist = {real_name:item.real_name,mobile:item.mobile,amount:item.amount,create_time:item.create_time,status:status,apply_time:item.apply_time,summary:item.summary};
			$("#datalistall").tmpl(datalist).appendTo('#datalist');
		});
	});	
}
function GetRequest() {  
   var url = location.search; //获取url中"?"符后的字串  
   var theRequest = new Object();  
   if (url.indexOf("?") != -1) {  
      var str = url.substr(1);  
      strs = str.split("&");  
      for(var i = 0; i < strs.length; i ++) {  
         theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);  
      }  
   }  
   return theRequest;  
}  
</script>

</body>
</html>

